#include "DataBase.hpp"
#include <string>

const std::string host = "localhost";
const std::string user = "shr";
const std::string passwd = "Monster.SHI.413.";
const std::string db = "conn_db";
const uint16_t port = 3306;

int main()
{
    DataBase::GetInstance()->Connect(host, user, passwd, db, port);
    // my.Connect();
    DataBase::GetInstance()->SetCharset("utf8");
    // // my.Query("insert into user (name, tel) values('Jack', '123456')");
    // // my.Query("insert into user (name, tel) values('张三', '11223')");
    // // my.Query("insert into user (name, tel) values('玛丽亚', '1112123')");
    DataBase::GetInstance()->Select("select name, tel from user");

    int rowNums = DataBase::GetInstance()->NumRows();
    int fieldNums = DataBase::GetInstance()->NumFields();
    std::cout << "row nums: " << rowNums << std::endl;
    std::cout << "fields nums: " << fieldNums << std::endl;

    MYSQL_FIELD* resFs = DataBase::GetInstance()->FetchFields();
    for (int i = 0; i < fieldNums; ++i) {
        std::cout << resFs[i].name << "\t";
    }
    std::cout << std::endl;
    for (int i = 0; i < rowNums; ++i)
    {
        MYSQL_ROW resR = DataBase::GetInstance()->FetchRow();
        for (int j = 0; j < fieldNums; ++j) {
            std::cout << resR[j] << "\t";
        }
        std::cout << std::endl;
    }
    DataBase::GetInstance()->ResFree();
    DataBase::GetInstance()->Close();
    return 0;
}